import 'package:flutter/material.dart';
import 'package:hkzf_flutter/pages/home/recommend/index_recommend_data.dart';
import 'package:hkzf_flutter/widgets/common_image.dart';

// 推荐列表默认数据列表
const List<IndexRecommendItem> indexRecommendData = [
   IndexRecommendItem(title:'家住回龙观',subTitle:'归属的感觉',imageUri:'static/images/home_index_recommend_1.png',navigateUri:'login'),
   IndexRecommendItem(title:'宜居四五环',subTitle:'大都市生活',imageUri:'static/images/home_index_recommend_2.png',navigateUri:'login'),
   IndexRecommendItem(title:'喧嚣三里屯',subTitle:'繁华的背后',imageUri:'static/images/home_index_recommend_3.png',navigateUri:'login'),
   IndexRecommendItem(title:'比邻十号线',subTitle:'地铁心连心',imageUri:'static/images/home_index_recommend_4.png',navigateUri:'login'),
];
const textStyle =  TextStyle(fontSize: 14.0, fontWeight: FontWeight.w500);


class IndexRecommend extends StatelessWidget {
  final List<IndexRecommendItem> dataList;

  const IndexRecommend({super.key, this.dataList = indexRecommendData});

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: const BoxDecoration(color:Color(0x08000000)),
      padding: const EdgeInsets.all(10.0),//  设置内边距
      child: Column(children: [
        const Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Text('房屋推荐',style: TextStyle(color: Colors.black,fontWeight: FontWeight.bold),),
          Text('更多',style: TextStyle(color: Colors.black54,fontWeight: FontWeight.w600),),
        ],),
        const Padding(padding: EdgeInsets.all(5)),
        Wrap(
          spacing: 10.0,// 水平间距
          runSpacing: 10.0,// 垂直间距
          children: dataList.map((item)=>Container(
            decoration: const BoxDecoration(
            ),
            child: RecommendItem(data: item)
          )).toList(),
        )
      ],),
    );
  }
}

// 推荐项内部结构
class RecommendItem extends StatelessWidget {
  final IndexRecommendItem data;
  const RecommendItem({super.key, this.data=const IndexRecommendItem()});

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () => {
        Navigator.of(context).pushNamed(data.navigateUri)
      },
      child: Container(
        decoration: const BoxDecoration(
          color: Colors.white,
          boxShadow: [
            BoxShadow(
              color: Color.fromARGB(255, 212, 212, 212), // 阴影颜色
              spreadRadius: 2, // 阴影扩散半径
              blurRadius: 6, // 模糊半径
              offset: Offset(0, 2), // 阴影偏移量(x轴,y轴)
            ),
          ],
        ),
        width: (MediaQuery.of(context).size.width - 10.0 * 3) /2,//MediaQuery.of(context).size.width:设备屏幕宽度
        padding: const EdgeInsets.all(10.0),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Column(
              mainAxisAlignment: MainAxisAlignment.start,
              children: [
                Text(data.title,style: textStyle,),
                Text(data.subTitle,style: textStyle,)
              ],
            ),
            Column(
              children: [
                CommonImage(
                   src:data.imageUri,
                   width: 60.0,
                )
              ],
            )
          ],
        ),
      ),
    );
  }
}